package com.hu.common.domain.base1;

import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hu.common.config.Config;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import java.util.List;

/**
 * @author 355760
 * @version 1.0
 * @description 分页基类
 */
@Data
public class BasePageDTO {

    @ApiModelProperty(value = "每页显示条数")
    @Min(1)
    private Integer pageSize;

    @ApiModelProperty(value = "当前页")
    @Min(1)
    private Integer current;

    public Integer getPageSize() {
        return this.pageSize = ObjectUtil.isNull(pageSize) ? 10 : pageSize > Config.maxPageSize ? Config.maxPageSize : pageSize;
    }

    public Integer getCurrent() {
        return ObjectUtil.isNull(current) ? 1 : current;
    }

    @ApiModelProperty(value = "排序类型")
    private String sort="desc";

    @ApiModelProperty(value = "排序列")
    private String sidx="";

    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private long total;

    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private long records;

    public <T> List<T> setData(List<T> data, long records) {
        this.total = records;
        return data;
    }

    @ApiModelProperty(value = "关键字")
    private String keyword="";
}
